// 第三方库声明文件
/// <reference path"runoob.d.ts"/>
class Site{
    num_val = 13;
    static savl = 10;
    name():void{
        console.log("hi");
    }
}

var site = new Site();
site.name();

let arr:Array<number> = [1,2];

//可存储各种类型的数组
let arrayList:any[] = [1,false,"hello"];

//枚举
enum Color {Red,Green,Blue};
//感觉很像 interface
let C:Color = Color.Blue;
console.log(C);
console.log(Color);

let num:number|null|string;

//定义返回值类型
function test(msg:string):never {
    console.log("I am test.");
    throw new Error(msg);
}

//无法被执行 到终点的方法
function loop():never{
    while(true){

    };
}

const getValue = ()=>{
    return 0;
}

enum List{
    A = getValue(),
    B = 3,
    C
}
console.log(List);
console.log(List.A);
console.log(List.B);
console.log(List.C);

let type:any = 1;
type = "22";
console.log("any:");
console.log(type);

function buildName(firstName: string, ...restOfName: string[]) {
    return firstName + " " + restOfName.join(" ");
}

let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie");
console.log(`employeeName: ${employeeName}`);


function addNumbers(...nums:number[]){
    var i;
    var sum:number = 0;
    for(i=0;i<nums.length;i++){
        sum = sum+nums[i];
    }
    console.log(`和为:${sum}`);
}
addNumbers(1,2,3); //6
addNumbers(10,10,10,10,10);  //50

var myFunc = new Function("a","b","return a*b;");
console.log(myFunc);

var foo = (x:number)=>10+x;

function disp(s1:string):void;
function disp(n1:number,s1:string):void;

function disp(x:any,y?:any):void{
    console.log(NaN);
    console.log(`输出了:${x},${y}`);
}

// function disp(x:number, y:number):void{
//     console.log(`x+y,输出了:${x+y}`);
// }
disp('hello');
disp(10,'world');

//接口
interface IPerson{
    age: number,
    firstName: string,
    lastName: string,
    sayHi: ()=>string
}

interface Musician extends IPerson{
    instrument: string
}

var drummer = <Musician>{};
drummer.age = 27;
drummer.instrument = "Drums";
console.log(`年龄：${drummer.age}`);
console.log(`喜欢的乐器: ${drummer.instrument}`);

var customer:IPerson= {
    age: 30,
    firstName: "Tom",
    lastName: "Hanks",
    sayHi: ():string=>{
        return "Hi there";
    }
}

console.log("Customer 对象 ");
console.log(customer.firstName);
console.log(customer.lastName);
console.log(customer.sayHi());

interface IParent1{
    v1: number
}

interface IParent2{
    v2: number
}

interface Child extends IParent1, IParent2{  }

var Iobj:Child = {v1: 12,v2: 23};
console.log(`value 1: ${Iobj.v1},  ${Iobj.v2}`);

//类
class Car{
    engine: string = "hello";  //原型属性
    constructor(engine:string){
        this.engine = engine;
    }
    disp():void{
        console.log(`发动机为：${this.engine}`);
    }
}

var car = new Car("马自达");
console.log(`Car 的实例属性：${car.engine}`);
console.log(car);
// console.log(`Car 的原型属性：${car.__proto__.engine}`);

//类的继承
class Shape{
    Area: number;
    constructor(a:number){
        this.Area = a;
    }
}

//继承就是复制实例、原型属性和方法，子类原型指向父类原型
class Circle extends Shape{
    static radius:number = 10;
    disp():void{
        console.log(`圆的面积：${this.Area}`);
    }
}

var obj = new Circle(223);
obj.disp();

class Encapsulate{
    str1:string = "hello";
    private str2:string = "world";
}

var obj1 = new Encapsulate();
console.log(obj1.str1);
// console.log(obj1.str2);

//对象
var sites = {
    site1: "Runoob",
    site2: "Google",
    sayHello: function(){
        console.log(`hello ${sites.site1}`);
    }
};

// sites.sayHello = function(){
//     console.log(`hello ${sites.site1}`);
// }

sites.sayHello();